package com.sskj.finance.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.finance.bean.AccountBean;
import com.sskj.finance.bean.TradeAccountBean;
import com.sskj.finance.http.HttpConfig;
import com.sskj.finance.ui.activity.TradeAccountActivity;
import com.sskj.lib.http.JsonCallBack;


public class TradeAccountActivityPresenter extends BasePresenter<TradeAccountActivity> {


    /**
     * 理财账户
     *
     * @return
     */
    public void financeAccount() {
        httpService.financeAccount().execute(new JsonCallBack<HttpData<AccountBean>>() {
            @Override
            public void onSuccess(Response<HttpData<AccountBean>> response) {
                HttpData<AccountBean> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {
                    mView.updateUI(httpData.getData());
                }
            }
        });
    }


    public void tradeAccount() {
        httpService.tradeAccount()
                .execute(new JsonCallBack<HttpData<TradeAccountBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<TradeAccountBean>> response) {
                        HttpData<TradeAccountBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            AccountBean accountBean = new AccountBean();
                            accountBean.setTtl_cnymoney(httpData.getData().getRes().getTotal().getTtl_cnymoney());
                            accountBean.setTtl_money(httpData.getData().getRes().getTotal().getTtl_money());
                            accountBean.setAsset(httpData.getData().getRes().getAsset());
                            mView.updateUI(accountBean);

                        }
                    }
                });
    }

    public void getData(boolean isTrade) {
        if (isTrade) {
            tradeAccount();
        } else {
            financeAccount();
        }
    }
}
